<!DOCTYPE html>
<html lang="zh-Hans" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>会诊会次统计</title>
    <script src="/static/common/js/echarts.min.js"></script>
    <script src="/static/common/js/common.js"></script>
    <link type="text/css" rel="stylesheet" href="css/countAll.css">
    <div th:replace="cqzd/common/common-resource :: global-header"></div>
</head>
<body>
    <div class="search-condition" style="width:100%;">
            <div id="form1">
                <table style="padding: 5px;" class="table" border="0px" cellspacing="5px" cellpadding="5px" align="center">
                    <tr>
                        <td width="240px">报表类型：
                            <input class="mini-combobox txk-dict" id="statType" dict="CQ_BASE_STAT_TYPE" value="1" onvaluechanged="showDateWidget();"/>
                        </td>
                        <td width="240px">
                            <div id="selectStatType">
                                时间：<input class="mini-datepicker" id="selectTime" format="yyyy/MM/dd"/>
                            </div>
                        </td>
                        <td class="btn-wrap" width="240px">
                            <input class="mini-button" text="查询" onclick="search" iconCls="icon-search"/>
                        </td>
                    </tr>
                </table>
            </div>
        <span id="countVal" style="font-size: 20px;position: relative;right: -85%;font-weight: bold;font-family: '宋体';"></span>
    </div>

<div class="mini-fit" style="padding:10px 5px 5px 5px;">
    <div id="main" style="width: 100%;height: 100%"></div>
</div>

<script type="text/javascript">
    var currentDate = new Date();
    txkui.parse();
    mini.get("selectTime").setValue(currentDate);
    setVisualData();
    var moduleUlr="cqzd/statistics/",modulePageUlr= getHtmlPageUrl("dib_count");

    //根据选择统计类型显示查询时间
    function showDateWidget () {
        var statType=mini.get("statType").value;
        var dayWidget="时间：<input class=\"mini-datepicker\" id=\"selectTime\" value=\""+currentDate+"\" format=\"yyyy/MM/dd\" />";
        var monthWidget="时间：<input class=\"mini-monthpicker\" id=\"selectTime\" value=\""+currentDate+"\" format=\"yyyy/MM\" />";
        var yearWidget="时间：<input class=\"mini-monthpicker\" id=\"selectTime\" value=\""+currentDate+"\" format=\"yyyy\" />";
        switch(statType){
            case "1":
                document.getElementById("selectStatType").innerHTML=dayWidget;
                txkui.parse();
                break;
            case "2":
                document.getElementById("selectStatType").innerHTML=dayWidget;
                txkui.parse();
                break;
            case "3":
                document.getElementById("selectStatType").innerHTML=monthWidget;
                txkui.parse();
                break;
            case "4":
                document.getElementById("selectStatType").innerHTML=yearWidget;
                txkui.parse();
                break;
            case "5":
                document.getElementById("selectStatType").innerHTML=yearWidget;
                txkui.parse();
                break;
            default:
                mini.showTips({
                    content:"统计类型数据错误！",
                    state:"danger",
                    x:"center",
                    y:"top",
                    timeout:3000
                });
                txkui.parse();
        }
    }

    //设置可视化统计数据
    function setVisualData() {
        //1.基于准备好的dom，初始化echarts实例
        var myChart=echarts.init(document.getElementById("main"));

        ////2.指定图表的配置项和数据
        var statType=mini.get("statType").value;
        var title="";    //标题
        var subTitle="";  //副标题
        var countNumber = 0;  //总人数

        var model={};
        var visit=new Array();
        var xAxis= new Array();
        switch(statType){
            case "1":
                title="孕妇患者检查会诊次数日统计";
                xAxis= new Array('0时','1时','2时','3时','4时','5时','6时','7时','8时','9时','10时','11时','12时',
                    '13时','14时','15时','16时','17时','18时','19时','20时','21时','22时','23时');

                var recordDate=mini.get("selectTime").value.format("yyyy/MM/dd");
                model.recordDay=recordDate;
                subTitle="统计时间："+model.recordDay;
                $.ajaxSettings.async = false;
                $.post("cqzd/stat/queryDibCountByDay",model,function(text){
                    for(var i=0;i<24;i++){     //24小时数据
                        for(var j=0;j<text.data.length;j++){
                            if(i==text.data[j].recordHour){
                                visit[i]=text.data[j].dibCount;
                                countNumber += text.data[j].dibCount;
                                break;
                            }
                            else
                                visit[i]=0;
                        }
                    }
                    $('#countVal').text('总检查会诊次数：'+countNumber);
                    return visit;
                });
                $.ajaxSettings.async = true;
                break;
            case "2":
                title="孕妇患者检查会诊次数周统计";
                var xAxisDay =new Array();
                var recordDate=mini.get("selectTime").value;
                var endDate=recordDate.format("yyyy/MM/dd");
                var tmpStartDate= new Date();
                tmpStartDate.setTime(recordDate.getTime());
                var startDate= new Date(tmpStartDate.setDate(tmpStartDate.getDate()-6)).format("yyyy/MM/dd");

                var tmpRecordDate=new Array();
                //let date2 = new Date();
                //date2.setTime(recordDate.getTime());
                for(var i=0;i<7;i++){
                    tmpRecordDate[i]=new Date();
                    tmpRecordDate[i].setTime(recordDate.getTime());
                    xAxis[i]=new Date(tmpRecordDate[i].setDate(tmpRecordDate[i].getDate()-(6-i))).format("yyyy/MM/dd");
                    xAxisDay[i]=tmpRecordDate[i].getDate();
                }

                model.startDate=startDate;
                model.endDate=endDate;
                subTitle="统计时间："+model.startDate+" 至 "+model.endDate;
                $.ajaxSettings.async = false;
                $.post("cqzd/stat/queryDibCountByWeek",model,function(text){
                    for(var i=0;i<7;i++){     //7天数据
                        for(var j=0;j<text.data.length;j++){
                            if(xAxisDay[i]==text.data[j].recordDay){
                                visit[i]=text.data[j].dibCount;
                                countNumber += text.data[j].dibCount;
                                break;
                            }
                            else
                                visit[i]=0;
                        }
                    }
                    $('#countVal').text('总检查会诊次数：'+countNumber);
                    return visit;
                });
                $.ajaxSettings.async = true;


                break;
            case "3":
                title="孕妇患者检查会诊次数月统计";
                var recordDate=mini.get("selectTime").value;
                var xAxisDay =new Array();
                var endDateOrg=new Date(recordDate.getFullYear(),recordDate.getMonth()+1,0);
                var endDay=endDateOrg.getDate();
                var endDate=endDateOrg.format("yyyy/MM/dd");

                var startDateOrg= new Date(recordDate.getFullYear(),recordDate.getMonth(),1);
                var startDate= startDateOrg.format("yyyy/MM/dd");

                var tmpStartDate=new Array();
                for(var i=0;i<endDay;i++){
                    tmpStartDate[i]=new Date();
                    tmpStartDate[i].setTime(startDateOrg.getTime());

                    xAxis[i]=new Date(tmpStartDate[i].setDate(tmpStartDate[i].getDate()+i)).format("dd") + "日";
                    xAxisDay[i]=tmpStartDate[i].getDate();
                }

                model.recordMonth=recordDate.format("yyyy/MM");
                subTitle="统计时间："+model.recordMonth;
                $.ajaxSettings.async = false;
                $.post("cqzd/stat/queryDibCountByMonth",model,function(text){
                    for(var i=0;i<endDay;i++){     //一个月中每天数据
                        for(var j=0;j<text.data.length;j++){
                            if(xAxisDay[i]==text.data[j].recordDay){
                                visit[i]=text.data[j].dibCount;
                                countNumber += text.data[j].dibCount;
                                break;
                            }
                            else
                                visit[i]=0;

                        }
                    }
                    $('#countVal').text('总检查会诊次数：'+countNumber);
                    return visit;
                });
                $.ajaxSettings.async = true;
                break;
            case "4":
                title="孕妇患者检查会诊次数季统计";
                var recordDate=mini.get("selectTime").value;
                xAxis= new Array('第一季度','第二季度','第三季度','第四季度');
                xAxisValue= new Array('1','2','3','4');
                model.recordYear=recordDate.format("yyyy");
                subTitle="统计时间： "+model.recordYear+" 年";
                $.ajaxSettings.async = false;
                $.post("cqzd/stat/queryDibCountByQuarter",model,function(text){
                    for(var i=0;i<4;i++){     //季度数据
                        for(var j=0;j<text.data.length;j++){
                            if(xAxisValue[i]==text.data[j].recordQuarter){
                                visit[i]=text.data[j].dibCount;
                                countNumber += text.data[j].dibCount;
                                break;
                            }
                            else
                                visit[i]=0;
                        }
                    }
                    $('#countVal').text('总检查会诊次数：'+countNumber);
                    return visit;
                });
                $.ajaxSettings.async = true;

                break;
            case "5":
                title="孕妇患者检查会诊次数年统计";
                var recordDate=mini.get("selectTime").value;
                xAxis= new Array('1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月');
                xAxisValue= new Array('01','02','03','04','05','06','07','08','09','10','11','12');
                model.recordYear=recordDate.format("yyyy");
                subTitle="统计时间： "+model.recordYear+" 年";
                $.ajaxSettings.async = false;
                $.post("cqzd/stat/queryDibCountByYear",model,function(text){
                    for(var i=0;i<12;i++){     //年数据
                        for(var j=0;j<text.data.length;j++){
                            if(xAxisValue[i]==text.data[j].recordMonth){
                                visit[i]=text.data[j].dibCount;
                                countNumber += text.data[j].dibCount;
                                break;
                            }
                            else
                                visit[i]=0;
                        }
                    }
                    $('#countVal').text('总检查会诊次数：'+countNumber);
                    return visit;
                });
                $.ajaxSettings.async = true;
                break;
            default:
                mini.showTips({
                    content:"统计标题数据错误！",
                    state:"danger",
                    x:"center",
                    y:"top",
                    timeout:3000
                });
        }

        var option = {
            title:{
                text:title,
                subtext:subTitle,
                x:"center",
                y:"top"
            },
            legend: {
                orient : 'horizontal',       //布局方式:'horizontal' |'vertical'
                x:"right",
                y:"center",
                padding: [
                    5,  // 上
                    20, // 右
                    5,  // 下
                    10, // 左
                ],
            },
            tooltip: {
                //trigger:'item',
                //formatter:"{a} <br/>{b} : {c}"
            },
            toolbox: {
                show : true,
                feature : {
                    mark : {show: false},
                    dataView : {show: true, readOnly: false},
                    magicType : {show: true, type: ['line', 'bar']},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            /*
            dataset: {
                source: [
                    ['product', '2015', '2016', '2017'],
                    ['Matcha Latte', 43.3, 85.8, 93.7],
                    ['Milk Tea', 83.1, 73.4, 55.1],
                    ['Cheese Cocoa', 86.4, 65.2, 82.5],
                    ['Walnut Brownie', 72.4, 53.9, 39.1]
                ]
            },*/
            xAxis: {
                type: 'category',
                //boundaryGap : false,
                data:xAxis
            },
            yAxis: {},
            // Declare several bar series, each will be mapped
            // to a column of dataset.source by default.
            series: [
                {
                    type: 'bar',
                    name:'人次',
                    smooth:true,      //平滑显示
                    showAllSymbol:true,
                    data:visit
                }
            ]
        };

        //使用刚指定的配置项和数据显示图表
        myChart.setOption(option);
    }


    function search(){
        setVisualData();
    }


</script>

</body>
</html>